<template>
	<view>
	<u-navbar back-text="管理员" :customBack="back" backIconColor="#fff" :backTextStyle="{'color':'#fff'}" :background="background"></u-navbar>
	<view class="content" v-if="logined">
		<view class="title">学生信息修改</view>
		<u-form-item left-icon="account" label-width="120" prop="stuNumber">
			<u-input type="text" class="u-border-bottom u-m-b-20" v-model="stu.stuNumber" placeholder="请输入要修改学生的学号" />
		</u-form-item>
		<u-form-item label="要修改的内容" label-width="200" prop='stuNumber'>
			<u-input v-model="form.major" type="select" border: true @click="showmajor=true" />
			<u-select v-model="showmajor" mode="single-column" :list="majorlist" @confirm="confirmmajor"
				@click="majorback"></u-select>
		</u-form-item>
		<u-form-item left-icon="lock" label-width="120" :prop="data1">
			<u-input type="text" class="u-border-bottom u-m-b-20" v-model="shu" placeholder="请输入新的值" />
		</u-form-item>
		<u-button @click="shanchu()">点击修改</u-button>
		<u-modal v-model="xiugai" :show-title="false" @confirm="confirm()" @cancel="cancel()" :showCancelButton="true">
			<view class="u-p-30">你确定要修改该信息吗？</view>
		</u-modal>
	</view>
	
	</view>
</template>

<script>
	export default {
		data() {
			return {
				shu:"",
				stu:{
					stuNumber:"",
					pwd:"",
					idNumber:"",
					name:""
				},
				form:{
					major:"",
					value:""
				},
				data1:"",
				showmajor: false,/////专业
				majorlist: [{
						value: '1',
						label: '账号密码'
					},
					{
						value: '2',
						label: '学生身份证号'
					},
					{
						value: '3',
						label: '学生姓名'
					}
				],
				xiugai:false,
				logined:true,
				background: {
					'background-image': 'linear-gradient(45deg, #2BC3C8, #84E7B9)'
				},
			}
		},
		onLoad() {
		},
		onShow(){
			if(this.form.value=="1"){
				this.data1=="pwd"
			}else if(this.form.value=="2"){
				this.data1=="idNumber"
			}else if(this.form.value=="3"){
				this.data1=="name"
			}
		},
		computed: {
			inputStyle() {
				let style = {};
				if(this.mobile) {
					style.color = "#fff";
					style.backgroundColor = '#2BC3C8';
				}
				return style;
			}
		},
		methods:{
			confirmmajor(major) {
				this.form.value=major[0].value;
				this.form.major = major[0].label;
				console.log(this.form)
			},
			cancel(){
				this.xiugai=false
			},
			shanchu(){
				if(this.stu.stuNumber==""){
					uni.showToast({
						title: '请输入学生账号名',
						icon: 'none'
					});
					return;
				}
				if(this.form.value==""){
					uni.showToast({
						title: '请选择要修改的内容',
						icon: 'none'
					});
					return;
				}
				if(this.shu==""){
					uni.showToast({
						title: '请输入新值',
						icon: 'none'
					});
					return;
				}
				this.xiugai=true
			},
			toHome(){
				uni.switchTab({
					url: "/pages/mine/index"
				})
			},
			twist(){
				uni.navigateTo({
					url:"/pages/login/chaxun"
				})
			},
			back(){
				this.$common.switchTabTo('/pages/index/index');
			},
			confirm(){
				if(this.form.value=="1"){
					this.stu.pwd=this.shu
					uni.request({
					 	url:"http://192.168.137.139:8080/adminChangeStuPwd",
						method:"POST",
						data:this.stu,
						success: (res) => {
						 if (res.data.code*1==200) {
							 try{
								 this.$u.toast('修改成功')
								console.log(res)
							 }catch(e){
								this.$u.toast('身份信息格式异常')
							 }
						 } else{
							this.$u.toast('修改失败，请确定输入正确的学号')
							console.log(res)
						 }
						}
					})
				}else if(this.form.value=="2"){
					this.stu.idNumber=this.shu
					uni.request({
					 	url:"http://192.168.137.139:8080/adminChangeStuIdNum",
						method:"POST",
						data:this.stu,
						success: (res) => {
						 if (res.data.code*1==200) {
							 try{
								 this.$u.toast('修改成功')
								console.log(res)
							 }catch(e){
								this.$u.toast('身份信息格式异常')
							 }
						 } else{
							this.$u.toast('修改失败，请确定输入正确的学号')
							console.log(res)
						 }
						}
					})
				}else if(this.form.value=="3"){
					this.stu.name=this.shu
					uni.request({
					 	url:"http://192.168.137.139:8080/adminChangeStuName",
						method:"POST",
						data:this.stu,
						success: (res) => {
						 if (res.data.code*1==200) {
							 try{
								 this.$u.toast('修改成功')
								 // setTimeout(function(){
								 // 	uni.navigateBack()
								 // },1000);
								console.log(res)
							 }catch(e){
								this.$u.toast('身份信息格式异常')
							 }
						 } else{
							this.$u.toast('修改失败，请确定输入正确的学号')
							console.log(res)
						 }
						}
					})
				}
				
			},
		}
		}
	
</script>

<style lang="scss" scoped>
	.content {
		margin: 80rpx 60rpx 30rpx 60rpx;
	
		.title {
			text-align: center;
			font-size: 60rpx;
			font-weight: 500;
			margin-bottom: 100rpx;
		}
	
		.getCaptcha {
			background-color: #A9FFDA;
			color: #FFFFFF;
			border: none;
			font-size: 30rpx;
			margin: 60rpx 0;
			
			&::after {
				border: none;
			}
		}
		.alternative {
			color: $u-tips-color;
			display: flex;
			justify-content: space-between;
			margin-top: 30rpx;
		}
	}
	.buttom {
		.loginType {
			display: flex;
			padding: 200rpx 150rpx 150rpx 150rpx;
			justify-content:space-between;
			
			.item {
				display: flex;
				flex-direction: column;
				align-items: center;
				color: $u-content-color;
				font-size: 28rpx;
			}
		}
		
		.hint {
			padding: 20rpx 40rpx;
			font-size: 20rpx;
			color: $u-tips-color;
			text-align: center;
			.link {
				color: $u-type-warning;
			}
		}
	}
</style>


